package com.company.bookstore.entities.user_admin_module;


import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Collection;

/**
 * <p>
 * 用户表
 * </p>
 * #            用户表：密码需要使用passwordencoder加密存储
 * CREATE TABLE `user` (
 * id INT PRIMARY KEY AUTO_INCREMENT,
 * username VARCHAR(20) UNIQUE,  # 用户名
 * `password` VARCHAR(255), # 密码
 * email VARCHAR(255),  # 邮箱
 * phone VARCHAR(11),    # 手机号tmp_add TEXT,     # 冗余地址值 为 country + province + city + town + detail
 * enabled INT DEFAULT 1,      #启用：1，禁用：0
 * deleted INT DEFAULT 0       #是否删除，0：未删除状态，1：删除状态
 * );
 *
 * @author 吴经纶
 * @blame Android Team
 * @since 2020-08-27
 */


@Builder
@Data
@TableName("t_user")
@NoArgsConstructor
@AllArgsConstructor
public class User implements UserDetails {

    private static final long serialVersionUID = 1L;
    @TableId(type = IdType.AUTO)
    private Integer id;
    /**
     * 用户名
     */
    private String username;
    /**
     * 密码
     */
    private String password;
    /**
     * 邮箱
     */
    private String email;
    /**
     * 手机号
     */
    private String phone;
    /**
     * 地址冗余值
     */
    private String tempAdd;
    /**
     *    #启用：1，禁用：0
     */
    private Integer enable;
    /**
     * 是否删除，0：未删除状态，1：删除状态

     */
    private Integer deleted;
    /**
     * 是否删除，0：男，1：女
     */
    private Boolean gender;

    private String avatar;
    private Integer fkAddressId;

//    @TableField(exist = false)
////    @BindEntity(entity = Address.class, condition = "fk_address_id = id")
//    private Address address;

    @Override
    public String getUsername() {
        return username;
    }
    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return null;
    }

    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    @Override
    public boolean isEnabled() {
        return enable==1;
    }
}
